package com.lalameow.researchstation.screen.widget

import com.lalameow.researchstation.util.MinecraftClient
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.gui.DrawableHelper
import net.minecraft.item.ItemStack
import net.silkmc.silk.core.task.infiniteMcCoroutineTask
import kotlin.time.Duration.Companion.seconds

@Environment(EnvType.CLIENT)
internal class DynamicItemIconWidget(private val icons: List<ItemStack>) : DrawableHelper() {
    private var currentIcon = 0

    init {
        infiniteMcCoroutineTask(
            client = true,
            period = 1.seconds
        ) {
            if (currentIcon == icons.size - 1) currentIcon = 0
            else ++currentIcon
        }
    }

    fun draw(x: Int, y: Int) {
        MinecraftClient.itemRenderer.renderInGui(icons[currentIcon], x, y)
    }
}
